package com.atguigu.jxc.controller;

import com.atguigu.jxc.domain.ServiceVO;
import com.atguigu.jxc.entity.*;
import com.atguigu.jxc.service.PurchaseListGoodsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * ClassName: PurchaseListGoodsController
 * Description:
 * Date: 2022/1/17 15:17
 *
 * @version:
 * @since JDK 1.8
 */

@RestController
@RequestMapping("/purchaseListGoods")
public class PurchaseListGoodsController {


    @Autowired
    private PurchaseListGoodsService purchaseListGoodsService;

    @PostMapping("/save")
    public ServiceVO savePurchaseListGoods(PurchaseList purchaseList, String purchaseListGoodsStr, HttpSession session){

        try {
            purchaseListGoodsService.savePurchaseListGoods(purchaseList,purchaseListGoodsStr,  session);
            return new ServiceVO<>(100,"请求成功");

        }catch (Exception e){
            e.printStackTrace();
        }
        return new ServiceVO<>(101,"添加或修改失败");


    }


    @PostMapping("/list")
    public Map<String,Object> getPurchaseListGoods(String purchaseNumber, Integer supplierId, Integer state, String sTime,String eTime){
        List<PurchaseList> purchaseListList = purchaseListGoodsService.getPurchaseListGoods(purchaseNumber,supplierId,state,sTime,eTime);


        HashMap<String, Object> stringObjectHashMap = new HashMap<>();

        stringObjectHashMap.put("rows",purchaseListList);
        return stringObjectHashMap;
    }


    @PostMapping("/goodsList")
    public Map<String,Object> getGoodsList(Integer purchaseListId){
        List<PurchaseListGoods> purchaseListGoodsList = purchaseListGoodsService.getGoodsList(purchaseListId);


        HashMap<String, Object> stringObjectHashMap = new HashMap<>();

        stringObjectHashMap.put("rows",purchaseListGoodsList);
        return stringObjectHashMap;
    }

    @PostMapping("/delete")
    public ServiceVO deletePurchaseListGoods(Integer purchaseListId){


        try {
            purchaseListGoodsService.deletePurchaseListGoods(purchaseListId);
            return new ServiceVO<>(100,"请求成功");
        }catch (Exception e){
            e.printStackTrace();
        }
        return new ServiceVO<>(101,"删除失败");


    }


    @PostMapping("/updateState")
    public ServiceVO updateState(Integer purchaseListId){


        try {
            purchaseListGoodsService.updateState(purchaseListId);
            return new ServiceVO<>(100,"请求成功");
        }catch (Exception e){
            e.printStackTrace();
        }
        return new ServiceVO<>(101,"删除失败");


    }


    @PostMapping("/count")
    public List<PurchaseListGoodsCount> count(String sTime, String eTime , Integer goodsTypeId, String codeOrName){



        List<PurchaseListGoodsCount> purchaseListGoodsCountList = purchaseListGoodsService.count(sTime, eTime ,goodsTypeId, codeOrName);


        return purchaseListGoodsCountList;




    }



}
